namespace Example
{
    using System;
    using System.Security.Principal;
    using System.ServiceModel;

    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class CalculatorService : ICalculator
    {
        /// <summary>
        /// Host the service within this EXE console application.
        /// </summary>
        public static void Main()
        {
            // Create a ServiceHost for the CalculatorService type and provide the base address.
            using (var serviceHost = new ServiceHost(typeof(CalculatorService)))
            {
                // Open the ServiceHostBase to create listeners and start listening for messages.
                serviceHost.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name);
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();
            }
        }

        public double Add(double operand1, double operand2)
        {
            var result = operand1 + operand2;
            Console.WriteLine("Received Add({0},{1})", operand1, operand2);
            Console.WriteLine("Return: {0}", result);
            return result;
        }

        public double Divide(double operand1, double operand2)
        {
            var result = operand1 / operand2;
            Console.WriteLine("Received Divide({0},{1})", operand1, operand2);
            Console.WriteLine("Return: {0}", result);
            return result;
        }

        public double Multiply(double operand1, double operand2)
        {
            var result = operand1 * operand2;
            Console.WriteLine("Received Multiply({0},{1})", operand1, operand2);
            Console.WriteLine("Return: {0}", result);
            return result;
        }

        public double Subtract(double operand1, double operand2)
        {
            var result = operand1 - operand2;
            Console.WriteLine("Received Subtract({0},{1})", operand1, operand2);
            Console.WriteLine("Return: {0}", result);
            return result;
        }
    }
}